package com.example.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.dao.UserDao;
import com.example.demo.pojo.UserPojo;
import lombok.val;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl {

    @Autowired
    UserDao userDao;

    public void addUser(String userName, String passWord){
        userDao.insert(new UserPojo(userName, passWord));
    }

    public void delUser(String userName){
        userDao.deleteById(userName);
    }

    public void findUserByName(String userName){
        UserPojo pojo = userDao.selectOne(new QueryWrapper<UserPojo>().eq("username", userName));
        System.out.println(pojo);
    }

    public void findUserListByName(String userName){
        List<UserPojo> pojo = userDao.selectList(new QueryWrapper<UserPojo>().like("username", userName));
        pojo.forEach(item -> {
            System.out.println(item);
        });

    }

    public void updateUserByUsername(String userName){
        UserPojo pojo = userDao.selectById(userName);
        pojo.setPassword("abcdefg");
        userDao.update(pojo, new QueryWrapper<UserPojo>().eq("username", userName));
    }
}
